package Test3;

import java.util.Scanner;
class Mod{
    public int code;//状态
    public int hang;
    public int lie;

    public String  way;//朝向

    public int concur;//占领的格子数
    public Mod(int hang,int lie,String way,int code) {
        this.hang = hang;
        this.lie = lie;
        this.way=way;
        concur=1;
        this.code=code;
    }
    //上移
    public void UpMove(int[][] place){
        this.way="Up";
        if(this.hang == 0) return;
        if(place[hang-1][lie] != this.code){
            return;
        } else {
          place[hang-1][lie] = this.code;
          this.hang--;
            concur++;
        }
    }

    /**
     * 下移
     */
    public void DownMove(int[][] place){
        this.way="Down";
        if(this.hang == 15) return;
        if(place[hang+1][lie] != this.code){
            return;
        } else {
            place[hang+1][lie] = this.code;
            this.hang++;
            concur++;
        }
    }
    /**
     * 左移
     */
    public void LeftMove(int[][] place){
        this.way="Left";
        if(this.lie == 0) return;
        if(place[hang][lie-1] != this.code){
            return;
        } else {
            place[hang][lie-1] = this.code;
            this.lie--;
            concur++;
        }
    }
    /**
     * 右移
     */
    public void RightMove(int[][] place){
        this.way="Right";
        if(this.lie == 15) return;
        if(place[hang][lie+1] != this.code){
            return;
        } else {
            place[hang][lie+1] = this.code;
            this.lie++;
            concur++;
        }
    }

    /**
     * 开火2
     * @param m
     */
    public int Fire(Mod m){
        //返回1表示打到了，返回0表示没打到
        if(this.hang == m.hang){
            if(this.way.equals("Left") && m.lie < this.lie){
                return 1;
            }else if(this.way.equals("Right") && m.lie > this.lie){
                return 1;
            }else{
                return 0;
            }
        } else if (this.lie == m.lie) {
            if(this.way.equals("Up") && m.lie < this.lie){
                return 1;
            }else if(this.way.equals("Down") && m.lie > this.lie){
                return 1;
            }else{
                return 0;
            }
        }
        return 0;
    }

}
public class Test {
    public static char isWin(Mod dMod,Mod wMod,int round){
        if(round == 256){
            if (dMod.concur == wMod.concur) return 'P';
            return dMod.concur > wMod.concur?'D':'M';
        }
        if(dMod.hang == wMod.hang && dMod.lie == wMod.lie){
            return 'P';
        }
        return 'C';

    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        //d占领过就是1。w占领过就是2
        int[][] place=new int[16][16];
        String dOp=sc.nextLine();
        String wOp=sc.nextLine();
        Mod dMod=new Mod(0,0,"right",1);
        Mod wMod=new Mod(15,15,"left",2);
        int dwin=-1;
        int wwin=-1;
        for (int i = 0; i < 256; i++) {
            switch (dOp.charAt(i)){
                case 'U':
                    dMod.UpMove(place);
                    break;
                case 'D':
                    dMod.DownMove(place);
                    break;
                case 'L':
                    dMod.LeftMove(place);
                    break;
                case 'R':
                    dMod.RightMove(place);
                    break;
                case 'F':
                    dwin=dMod.Fire(wMod);
                    break;
            }
            switch (wOp.charAt(i)){
                case 'U':
                    wMod.UpMove(place);
                    break;
                case 'D':
                    wMod.DownMove(place);
                    break;
                case 'L':
                    wMod.LeftMove(place);
                    break;
                case 'R':
                    wMod.RightMove(place);
                    break;
                case 'F':
                    wwin=wMod.Fire(dMod);
                    break;
            }
            if (wwin == 1 && dwin == 1){
                System.out.println(i+1);
                System.out.println('P');
                return;
            } else if (wwin == 1 && dwin != 1) {
                System.out.println(i+1);
                System.out.println('W');
                return;
            }else if (wwin != 1 && dwin == 1){
                System.out.println(i+1);
                System.out.println('D');
                return;
            }else{
                char result=isWin(dMod,wMod,i+1);
                if(result == 'C'){
                    continue;
                }else {
                    System.out.println(i+1);
                    System.out.println(result);
                    return;
                }
            }
        }
    }
}